package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.RefuelingRecordMapper;
import com.woniuxy.pojo.RefuelingRecord;
import com.woniuxy.service.RefuelingRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.RefuelingRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RefuelingRecordImpl implements RefuelingRecordService{
    @Autowired
    private RefuelingRecordMapper refuelingRecordMapper;

    @Override
    public DataGridView selectRefuelingRecordsByProperty(RefuelingRecordVo refuelingRecordVo) {
        Page<Object> page = PageHelper.startPage(refuelingRecordVo.getPage(),refuelingRecordVo.getLimit());
        List<RefuelingRecord> records = this.refuelingRecordMapper.selectRefuelingRecordsByProperty(refuelingRecordVo);
        return new DataGridView(page.getTotal(),records);
    }
    @Transactional
    @Override
    public void deleteRefuelingRecordById(int id) {
        refuelingRecordMapper.deleteRefuelingRecordById(id);
    }

    @Override
    public void removeBatchRefuelingRecord(Integer[] ids) {
        if (ids!=null&&ids.length>0){
            for (Integer id:ids){
                this.deleteRefuelingRecordById(id);
            }
        }
    }

    @Override
    public boolean insertDrvingRecord(RefuelingRecord refuelingRecord) {
        boolean flag=false;
        int i = this.refuelingRecordMapper.insertRefuelingRecord(refuelingRecord);
        if(i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean updataDrvingRecord(RefuelingRecord refuelingRecord) {
        boolean flag=true;
        int i = this.refuelingRecordMapper.updataRefuelingRecord(refuelingRecord);
        if (i>0){
            flag=true;
        }
        return flag;
    }
}
